/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ept.controller;

import com.ept.entities.Commandeclient;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import org.primefaces.event.ToggleEvent;

/**
 *
 * @author Imen
 */
@ManagedBean ( name="achatController" )
@ViewScoped
public class AchatController implements  Serializable, ActionListener  {

 List<Commandeclient> list;
 List<Commandeclient> list1;
 private Commandeclient selectedProduit ;
 int total;

    public Commandeclient getSelectedProduit() {
        return selectedProduit;
    }

    public void setSelectedProduit(Commandeclient selectedProduit) {
        this.selectedProduit = selectedProduit;
    }

 
 
    public int getTotal() {
         total = 0;  
  
        for (Commandeclient current : list) {
            total += current.getPrix()*current.getQuantite(); 
        } 
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public List<Commandeclient> getList() {
        return list;
    }

    public void setList(List<Commandeclient> list) {
        this.list = list;
    }
 
 
 
  @EJB
    private com.ept.facade.CommandeclientFacade commandeclientFacade;
    /**
     * Creates a new instance of MonPanierController
     */
  
  
  

  
  @PostConstruct
    public String AfficherAchats(){
          LoginController loginController = (LoginController) FacesAccessor.getManagedBean("loginController"); 
         
        list = commandeclientFacade.findAchats(loginController.getUtilisateur().getPanier());    
          
        return "achats.xhtml?faces-redirect=true";
    }
    
    
     
    public AchatController() {
       
    }
    
    
    @Override
    public void processAction(ActionEvent event) throws AbortProcessingException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    }

